package com.example.studykotlin

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.IntDef
import androidx.appcompat.app.ActionBar
import androidx.recyclerview.widget.RecyclerView
import com.example.studykotlin.databinding.AdapterItemListBinding
import com.example.studykotlin.kotlin_actual_combat.Bean.ItemSingleClickMessage
import com.example.studykotlin.kotlin_actual_combat.annotation.EventMode
import org.greenrobot.eventbus.EventBus

/**
 *描述:
 *创建者：pjh
 *创建日期：2021/3/26
 *UpdateUser:更新者
 *更新时间：2021/3/26
 */

class ListAdapter(private val data: MutableList<String>) :
    RecyclerView.Adapter<ListAdapter.Holder>(){

    @get:EventMode
    @setparam:EventMode
    var eventMode: Int = EventMode.MAIN

    class Holder(itemView: AdapterItemListBinding) : RecyclerView.ViewHolder(itemView.root) {
        val tvText = itemView.tvText
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
        val view = AdapterItemListBinding.inflate(LayoutInflater.from(parent.context),parent,false)
        return Holder(view)
    }

    override fun onBindViewHolder(holder: Holder, position: Int) {
        holder.tvText.text = data[position]
        holder.tvText.setOnClickListener {
            EventBus.getDefault().post(ItemSingleClickMessage(position,eventMode))
        }
    }

    override fun getItemCount(): Int {
        return data.size
    }


}